(function (vc) {
    let DEFAULT_PAGE = 1;
    let DEFAULT_ROW = 10;
    vc.extends({
        data: {
            communityRepairTreeInfo: {
                parkings: [],
                callName: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('communityRepairTree', 'initCommunityRepairTree', function (_param) {
                $that.communityRepairTreeInfo.callName = _param.callName;
                $that._loadCommunityRepairTree();
            });
        },
        methods: {
            _loadCommunityRepairTree: function () {
                let param = {
                    params: {
                        hc:1.8
                    }
                };
                //发送get请求
                vc.http.apiGet('/community.queryCommunityRepairTree',
                    param,
                    function (json) {
                        let _json = JSON.parse(json);
                        $that.communityRepairTreeInfo.parkings = _json.data;
                        $that._initJsTreeCommunityRepairTree();
                    },
                    function () {
                        console.log('请求失败处理');
                    });
            },
            _initJsTreeCommunityRepairTree: function () {
                let _data = $that.communityRepairTreeInfo.parkings; 
                $.jstree.destroy()
                $("#jstree_communityRepairTreeDiv").jstree({
                    "checkbox": {
                        "keep_selected_style": false
                    },
                    'state': { //一些初始化状态
                        "opened": true,
                    },
                    'core': {
                        "check_callback": true,
                        'data': _data
                    }
                });
                $("#jstree_communityRepairTreeDiv").on("ready.jstree", function (e, data) {
                    //$('#jstree_communityRepairTreeDiv').jstree('select_node', _data[0].children[0].id /* , true */);
                });
                $('#jstree_communityRepairTreeDiv').on("changed.jstree", function (e, data) {
                    if (data.action == 'model' || data.action == 'ready') {
                        return;
                    }
                    let _selected = data.selected[0];
                    if (_selected.startsWith('c_')) {
                        vc.emit($that.communityRepairTreeInfo.callName, 'selectCommunity', {
                            communityName: data.node.original.communityName,
                            communityId: data.node.original.communityId
                        })
                        return;
                    }
                    if (_selected.startsWith('r_')) {
                        vc.emit($that.communityRepairTreeInfo.callName, 'selectRepairSetting', {
                            communityId: data.node.original.communityId,
                            repairType: data.node.original.repairType
                        })
                        return;
                    }
                    //console.log(_selected, data.node.original.unitId)
                    if (_selected.startsWith('s_')) {
                        vc.emit($that.communityRepairTreeInfo.callName, 'selectState', {
                            communityId: data.node.original.communityId,
                            repairType: data.node.original.repairType,
                            state: data.node.original.state,

                        })
                    }
                    
                });
                $('#jstree_communityRepairTreeDiv')
                    .on('click', '.jstree-anchor', function (e) {
                        $(this).jstree(true).toggle_node(e.target);
                    })
            },
        }
    });
})(window.vc);